home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / animatin / anim_q2z / statusdm / articles / gfabasic.asc < prev    next >
Encoding:
Text File  |  1995-04-26  |  7.8 KB  |  140 lines

  1. *******************************************************************************
  2. *                            STatus Disk Magazine                             *
  3. *                             Issue 1, Volume 1                               *
  4. *                                                                             *
  5. * NOTE:  This issue is to be copied freely by Atari ST users.  We at STatus   *
  6. * strictly prohibit anyone selling this issue as part of a Shareware or PD    *
  7. * collection.                                                                 *
  8. *                                                                             *
  9. *                            STatus Disk Magazine                             *
  10. *                            Suite 299                                        *
  11. *                            4431 Lehigh Road                                 *
  12. *                            College Park, MD  20740                          *
  13. *                                                                             *
  14. * STatus Disk Magazine (c) 1989, is a COMMERCIAL effort.                      *
  15. *******************************************************************************
  16.  
  17.                How to Display a Spectrum Picture in GFA Basic
  18.  
  19.  
  20.           Thanks to Trio Engineering's Spectrum 512,  we all can  enjoy 
  21.      seeing 320x200 pictures with 512 colors at  once.   However,  even 
  22.      now,  not  much  else in the realm of the Atari  ST  graphics  has 
  23.      broken the 16 color barrier,  and no other program has done it  in 
  24.      such  a clean method.   After using Quantum Paint 4096,  and  it's 
  25.      promised 4096 color at once display,  I was somewhat disappointed, 
  26.      since  it  was  to  use only 5%  of  the  ST's  CPU  time,  unlike 
  27.      Spectrum's  80%,  but  this is not a review  of  Spectrum,  but  a 
  28.      tutorial on how to work with Spectrum pictures in GFA Basic.
  29.  
  30.           For  this example,  I used GFA Basic v2.02 (now that the  GFA 
  31.      Compiler  for Basic v3.0 is out,  I'll upgrade!).   There are  two 
  32.      files required to make this work,  that were released into the  PD 
  33.      by Trio Engineering a while back.  These are:
  34.  
  35.           SHOW512.O  -   this  actually pre-empts the  normal  ST video 
  36.                          display   and  implements  what  I  term   the 
  37.                           "Spectrum technique".  
  38.           DECOMP.O   -   this is a module that will decompress an  .SPC 
  39.                          pic into a SPU format pic, which is the actual 
  40.                           display format Spectrum 512 pictures use.
  41.  
  42.          The Spectrum picture,  decompressed,  is always 51104  bytes.  
  43.      Here is the format of the picture:
  44.  
  45.           32000 bytes -  raw screen data
  46.           19104 bytes -  palette data
  47.  
  48.           The  19104  bytes  stems from the fact that  it  is  using  3 
  49.      palettes  per  scanline  for 199 (not  200)  scanlines,  and  each 
  50.      palette is 16 words (32 bytes).   So,  for each scanline,  1 - 199 
  51.      inclusive  (scanline  0  is always blank),  we have  96  bytes  of 
  52.      palette data, so the total is 199 * 96 bytes = 19104 bytes.
  53.  
  54.           Now  there are two main criteria to remember.   The first  is 
  55.      that the ST requires any displayable screen to have it's  starting 
  56.      address  be evenly divisible by 256.   This is because  the  video 
  57.      chip  cannot  truly access all 4 megabytes available from  the  ST 
  58.      MMU,  so, in order to allow for relocatable screens throughout a 4 
  59.      meg system, Atari made the video Shifter ignore the lowest byte of 
  60.      address data.  This means that when you reserve space for Spectrum 
  61.      picture,  you must give yourself about 255 bytes leeway,  in  case 
  62.      the  location is not evenly divisible by  256.   My  routine,  for 
  63.      a  GEM M_alloc (reserve memory) call will do  this  automatically, 
  64.      and   return in the variable "Adr" the address that is  acceptable.
  65.      If you note,  I reserve 104000 bytes, which is enough for two full 
  66.      size uncompressed pictures.   That is because I need 51104 for the 
  67.      decompressed displayable picture, and space for the picture before 
  68.      decompression.  The second criteria is  to boot  in  the  routines 
  69.      made by Trio, into "blanked" out areas of memory.  I  do  this  by 
  70.      zeroing  out a string of the same length as the module I  boot  in 
  71.      with  the SPACE$ command,  and then booting the module in  via  my 
  72.      loader routine. 
  73.  
  74.           Now  the  next step is the get the  filename  to  view.   The 
  75.      viewer uses the file selector, which is easily enough done in  GFA 
  76.      Basic.  If the user doesn't pick a file, it will terminate.  
  77.  
  78.           The final two steps are to call in the routines that actually 
  79.      decompress  the  .SPC file and display the  uncompressed  picture. 
  80.      Trio states that mouse routines will not work reliably,  and also, 
  81.      GEM file operations will wreck the display,  sending it back to 16 
  82.      color mode.   So,  when displaying a picture,  your best bet is to 
  83.      plan  for keyboard input only.   I do this via the INKEY$  so  the 
  84.      system  waits  for  a keypress before showing  the  file  selector 
  85.      again.
  86.  
  87.           The  variables  used  in  this  are  Spc%  (address  of   the 
  88.      uncompressed   picture  data),Bitm%  (address  of  the   bit   map 
  89.      data/screen   data..the  32000 byte portion  of  the  uncompressed 
  90.      picture),  and  Colm% (address of the palette/color  information). 
  91.      The two are made contiguous for my purposes,  but could reside  in 
  92.      totally different areas of memory.  When de-arc'ing the picture, I 
  93.      simply use:
  94.  
  95.           Dummy = C:Decom%(L:Spc%,Bitm%,L:Colm%)
  96.  
  97.           what this really does is says to GFA Basic is to run 
  98.      DECOMP.O, (which  we booted in,  and remembered the starting 
  99.      address  of  it as  Decom%!),  and to pass three longwords to it,  
  100.      which  are  the previously  described variables Spc%,  Bitm% and 
  101.  
  102.      Colm%.   We  also check  the  value for Dummy to make sure that it 
  103.      is a 0  which  is DECOMP.O's   way   of  telling  you  all  
  104.      went   well   with   the decompression.
  105.  
  106.           The display routine, SHOW512.O is called similarly.  We don't 
  107.      need to worry about an error code or any return value, so we use:
  108.  
  109.           Void C: Show%(1,L:Bitm%,L:Colm%)
  110.  
  111.           this calls the SHOW512.O routine, located at Show%, and tells 
  112.      it  to display,  using the "Spectrum Technique" the picture  whose 
  113.      address  (uncompressed)  is at Bitm% and whose palette is  at  the 
  114.      address  Colm%.   The number "1" you in the parentheses tells  the 
  115.      routine  how often to keep this screen up on display.   I send  it 
  116.      the value "1" to keep it up 1/60th of a second at a time.
  117.  
  118.           Now  that I have shown how to display a  Spectrum  compressed 
  119.      picture the next logical step would be animating them.   That  can 
  120.      be accomplished by booting in a series of pictures,  decompressing 
  121.      and using the display code with variable frame speeds.
  122.  
  123.           Another,  more  difficult  thing to try would  be  to  create 
  124.      vertical  scrolling through several Spectrum 512  pictures.   This 
  125.      would require setting up the palette data for all the pictures  in 
  126.      one area,  and put the pictures all together in another area,  and 
  127.      as you move through the pictures,  you increment a pointer to  the 
  128.      proper  address for the colors.   Perhaps this is material  for  a 
  129.      later GFA tutorial.
  130.  
  131.           Also,  in passing, I'd like to thank a BBSer who used to call 
  132.      LD to Washington,  D.C. named Pat Steele who helped me figure this 
  133.      out when the Trio code first became available.
  134.  
  135.           Finally,  I'd  like  to encourage others to  experiment  with 
  136.      this, and perhaps bring us a few 512 color programs!
  137.  
  138.  
  139.  
  140.